<?php

class Question{

	function __construct($id) {
		$query = mysql_query("SELECT * FROM `question` WHERE `id` = '$id'") or die(mysql_error());
		$result = mysql_fetch_object($query);
		if($result) {
			foreach($result as $key=>$value) {
				$this->$key = $value;
			}
		}
	}

	public function updateQuestion($data) {
		$sql = mysql_query("UPDATE `question` SET
			`type` = '$data->type',
			`required` = '$data->required',
			`question` = '$data->question',
			`create_section` = '$data->create_section',
			`order`='$data->order',
			`response1`='$data->response1',
			`response2`='$data->response2',
			`response3`='$data->response3',
			`response4`='$data->response4',
			`response5`='$data->response5',
			`response6`='$data->response6'
			WHERE `id`='$this->id';") 
		or die(mysql_error());
	}

	public function checkCondition($id) {
		$sql = "SELECT * FROM `branching` WHERE `question_1_id` = '$id'";
		$result = mysql_query($sql)or die("Check Condition:".mysql_error());
		$i = 0;
		while($c = mysql_fetch_object($result)) {
			$condition[$i]['question_2_id'] = $c->question_2_id;
			$condition[$i]['condition']=$c->condition;
			$condition[$i]['condition_value']= $c->value;
			$i++;
		}
		if($condition) {
			return $condition;
		} else {
			return false;
		}
	}

	public function deleteCondition($id) {
		$sql = "DELETE FROM `branching` WHERE `id`='$id'";
		$result = mysql_query($sql) or die("Delete Condition:".mysql_error());
	}
}
?>